//
// Created by 麻再挺 on 2021/12/15.
//

#include "parent_tree.h"


/**
 * 初始化
 * @param t 树
 */
Status PtTree_Init(PtTree *t) {
    int num = 10;
    int index[] = {-1, 0, 0, 0, 1, 1, 3, 6, 6, 6};
    char chs[] = {'R', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'K'};
    t->n = num;
    for (int i = 0; i < num; ++i) {
        t->node[i].data = chs[i];
        t->node[i].parent = index[i];
    }
    return OK;
}

/**
 * 查找元素
 * @param t 树
 * @param e 元素
 */
void PtTree_Find_Parent(PtTree *t, PtElemType e) {
    int isFind = 0;
    for (int i = 0; i < t->n; i++) {
        if (t->node[i].data == e) {
            isFind = 1;
            printf("%c的父节点为 %c,存储位置下标为 %d", e, t->node[i].data, t->node[i].parent);
            break;
        }
    }
    if (isFind == 0) {
        printf("树中无此节点");
    }
}

void PtTree_Print(PtTree *t) {
    for (int i = 0; i < t->n; ++i) {
        printf("index: %d,data: %c, parent: %d\n", i, t->node[i].data, t->node[i].parent);
    }
}
